﻿Imports DevExpress.XtraReports.UI

Public Class ReportDataKegiatan

    Private Sub LoadPeralatan(ByRef dtperalatan As DataTable, ByVal exQuery As String, ByVal exKriteria As String)
        Dim strQuery As String()
        Dim err As String = ""
        strQuery = New String() {exQuery, "dataperalatan", "namaalat", exKriteria}
        If exKriteria = "" Then
            If Utils.executeSP("proc_searchall", strQuery, dtperalatan) Then
                dtperalatan = dtperalatan
            End If
        Else
            If Utils.executeSP("proc_searchallEqual", strQuery, dtperalatan) Then
                dtperalatan = dtperalatan
            End If
        End If
        
    End Sub

    Private Sub LoadObat(ByRef dtperalatan As DataTable, ByVal exQuery As String, ByVal exKriteria As String)
        Dim strQuery As String()
        Dim err As String = ""
        strQuery = New String() {exQuery, "dataobat", "namaobat", exKriteria}
        If exKriteria = "" Then
            If Utils.executeSP("proc_searchall", strQuery, dtperalatan) Then
                dtperalatan = dtperalatan
            End If
        Else
            If Utils.executeSP("proc_searchallEqual", strQuery, dtperalatan) Then
                dtperalatan = dtperalatan
            End If
        End If

    End Sub

    Private Sub LoadHistoObat(ByRef dtperalatan As DataTable, ByVal exQuery As String, ByVal exKriteria As String)
        Dim strQuery As String()
        Dim err As String = ""
        strQuery = New String() {exQuery, "vhistoobat", "namaobat", exKriteria}
        If exKriteria = "" Then
            If Utils.executeSP("proc_searchall", strQuery, dtperalatan) Then
                dtperalatan = dtperalatan
            End If
        Else
            If Utils.executeSP("proc_searchallEqual", strQuery, dtperalatan) Then
                dtperalatan = dtperalatan
            End If
        End If

    End Sub

    Private Sub LoadKegiatan(ByRef dtkegiatan As DataTable, ByVal vMULAI As String, ByVal vSAMPAI As String)
        Dim strQuery As String()
        Dim err As String = ""
        strQuery = New String() {vMULAI, vSAMPAI}

        If Utils.executeSP("procgetkegiatan", strQuery, dtkegiatan) Then
            dtkegiatan.TableName = "datakegiatan"
            dtkegiatan = dtkegiatan
        End If


    End Sub

    Private Sub SimpleButton1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton1.Click
        Dim rep As New XtraReport
        Dim dt As New DataTable
        rep = New rptDATA_PERALATAN
        LoadPeralatan(dt, "*", IIf(cbPERALATAN.Text = "", cbPERALATAN.Text.Replace("Semua", ""), cbPERALATAN.Text.Replace("Semua", "")))
        BaseMain.LoadPreviewReport(rep, dt, Me.Name, Me.TitleHead)

    End Sub

    Private Sub ReportDataKegiatan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim dtperalatan As New DataTable
        LoadPeralatan(dtperalatan, "distinct namaalat", "")
        cbPERALATAN.Properties.Items.Add("Semua")
        For Each dtrow As DataRow In dtperalatan.Rows
            cbPERALATAN.Properties.Items.Add(dtrow(0))
        Next
        cbPERALATAN.SelectedIndex = 0
        Dim dtobat As New DataTable
        LoadObat(dtobat, "distinct namaobat", "")
        cbObat.Properties.Items.Add("Semua")
        For Each dtrow As DataRow In dtobat.Rows
            cbObat.Properties.Items.Add(dtrow(0))
        Next
        cbObat.SelectedIndex = 0
        deMULAI.DateTime = Now
        deSAMPAI.DateTime = Now
    End Sub

    Private Sub SimpleButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton2.Click
        Dim rep As New XtraReport
        Dim dt As New DataTable
        rep = New rptDAFTAR_OBAT
        LoadObat(dt, "*", cbObat.Text.Replace("Semua", ""))
        BaseMain.LoadPreviewReport(rep, dt, Me.Name, Me.TitleHead)
    End Sub

    Private Sub SimpleButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton3.Click
        Dim rep As New XtraReport
        Dim dt As New DataTable
        rep = New HISTOBAT
        LoadHistoObat(dt, "*", cbObat.Text.Replace("Semua", ""))
        BaseMain.LoadPreviewReport(rep, dt, Me.Name, Me.TitleHead)
    End Sub

    Private Sub SimpleButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton4.Click
        Dim rep As New XtraReport
        Dim dt As New DataTable
        rep = New rptKEGIATAN
        LoadKegiatan(dt, deMULAI.DateTime.ToString("yyyy-MM-dd"), deSAMPAI.DateTime.ToString("yyyy-MM-dd"))
        BaseMain.LoadPreviewReport(rep, dt, Me.Name, Me.TitleHead)
    End Sub
End Class
